package BinaryTree;

import java.util.List;

public class Test {
    public static void main(String[] args) {
        BinaryTree binaryTree=new BinaryTree();
        test1(binaryTree);
        test2(binaryTree);
        test3(binaryTree);
        BinaryTree binaryTree1=new BinaryTree();
        test4(binaryTree1);
    }
    public static void test1(BinaryTree binaryTree) {
        System.out.println("=============test1==============");
        binaryTree.creatTree();
        binaryTree.preOrder(binaryTree.root);
        System.out.println();
        binaryTree.inOrder(binaryTree.root);
        System.out.println();
        binaryTree.postOrder(binaryTree.root);
        System.out.println();
        System.out.println("=============test2===============");
    }
    public static void test2(BinaryTree binaryTree) {
        List<Character> list=binaryTree.preorderTraversal(binaryTree.root);
        System.out.println("前序递归结果:"+list);

        int size = binaryTree.size(binaryTree.root);
        System.out.println("子问题思想总结点个数:"+size);

        binaryTree.size1(binaryTree.root);
        System.out.println("遍历思想总结点个数:"+binaryTree.nodeSize);

        int leafcount=binaryTree.getLeafNodeCount(binaryTree.root);
        System.out.println("子问题思想叶子结点个数:"+leafcount);

        binaryTree.getLeafNodeCount1(binaryTree.root);
        System.out.println("遍历思想叶子结点个数:"+binaryTree.leafCount);

        int count=binaryTree.getLevelNodeCount(binaryTree.root,4);
        System.out.println("第k层结点的个数:"+count);
        System.out.println("=============test3===============");
    }
    public static void test3(BinaryTree binaryTree) {
        int height=binaryTree.getHeight(binaryTree.root);
        System.out.println("树的高度是:"+height);

        TreeNode node=binaryTree.find(binaryTree.root,'E');
        if(node==null) {
            System.out.println("不存在该结点!!!");
            return;
        }
        System.out.println("该节点的值为:"+node.val);

        System.out.print("层序遍历的结果:");
        binaryTree.levelOrder(binaryTree.root);
        System.out.println();

        System.out.print("非递归层序遍历的结果:");
        List<List<Character>> ret=binaryTree.levelOrder1(binaryTree.root);
        System.out.println(ret);

        TreeNode root=binaryTree.creatTree("abc##de#g##f###");
        System.out.print("前序遍历的结果为:");
        binaryTree.inOrder(root);
        System.out.println();
        System.out.println("=============test4===============");
    }
    public static void test4(BinaryTree binaryTree) {
        binaryTree.creatTree();
        boolean flg=binaryTree.isCompleteTree(binaryTree.root);
        System.out.print("判断完全二叉树:"+flg);
        System.out.println();

        Exercise exercise=new Exercise();
        TreeNode root=exercise.buildTree(new char[]{'E','F','H','I','G','J','K'},new char[]{'H','F','I','E','J','K','G'});
        System.out.print("根据前序和中序遍历得到的二叉树为：");
        binaryTree.postOrder(root);
    }

}
